package com.qdy.util;

import com.jiai.core.util.SpringUtil;
import com.qdy.entity.user.User;
import com.qdy.repository.UserRepository;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.swing.text.html.HTML;

/**
 * Created by Administrator on 2017/3/26.
 */
public class HttpUtil {
    private static Logger log= LoggerFactory.getLogger(HttpUtil.class);
    public static Long getUserId(){
        String  userId=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("userId");
        if(StringUtils.isEmpty(userId))
            return null;
        return Long.valueOf(userId);
    }
    public  static User getUser(){
        String  userId=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("userId");
        log.info("==================userId========================"+userId);
        if(StringUtils.isEmpty(userId))
            return null;
        return SpringUtil.getBean(UserRepository.class).findOne(Long.valueOf(userId));
    }
}
